{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card">
	<div class="layui-card-body">
		<div class="layui-card-header">
			<i class="fa fa-pencil"></i> 编辑区域
		</div>
		<form class="layui-form" action="">
			<input type="hidden" name="id" value="{$info.id}" />
			<div class="layui-form-item">
				<label class="layui-form-label">上级区域：</label>
				<div class="layui-input-inline">
					<select name="cat1" id="cat1" lay-filter="cat1">
						<option value="">请选择</option>
					</select>
				</div>
				<div class="layui-input-inline">
					<select name="cat2" id="cat2" lay-filter="cat2">
						<option value="">请选择</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">区域名称</label>
				<div class="layui-input-inline layui-input-wrap">
					<input type="text" name="name" lay-verify="required" value="{$info.name}" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<script src="/static/admin/js/cat_select.js?s=345"></script>
			<script>
				cat_select('cat1','cat2','cat3',"{$info.parent_id}","{$info.parent_id2}","","{:url('getRegion')}");
			</script>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
				</div>
			</div>
		</form>
	</div>
</div>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
	layui.use(['form', 'laydate', 'util'], function(){
		var form = layui.form;
		var layer = layui.layer;
		var laydate = layui.laydate;
		var util = layui.util;

		// 自定义验证规则
		form.verify({
			pass: [
				/^[\S]{6,12}$/,
				'密码必须6到12位，且不能出现空格'
			]
		});

		// 指定开关事件
		// form.on('switch(switchTest)', function(data){
		//     layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
		//         offset: '6px'
		//     });
		//     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
		// });

		// 提交事件
		form.on('submit(demo1)', function(data){
			var index = layer.load();
			layer.close(index);

			var field = data.field; // 获取表单字段值
			$.ajax({
				type: "POST",
				url: "{:url('edit_region')}",
				data: field,
				success: function(res){
					console.log(res);
					if(res.status){
						layer.msg('提交成功');
					}else{
						layer.msg(res.msg);
					}
					setTimeout(function(){
						parent.layer.closeAll();
						parent.tableIns.reload()
					},1000)
				}
			});
			return false; // 阻止默认 form 跳转
		});

		// 日期
		laydate.render({
			elem: '#date'
		});


	});
</script>
</body>
</html>